package com.ruicar.afs.jobadmin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruicar.afs.jobadmin.core.model.AfsJobLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * The type AfsJobLogMapper
 * <p>Description: </p>
 *
 * @author Fzero
 * @version 1.0
 * @date Created on 2020.06.13 14:17:11
 * @since 1.0
 */
@Mapper
public interface AfsJobLogMapper extends BaseMapper<AfsJobLog> {

    /**
     * Page list list
     *
     * @param offset           offset
     * @param pagesize         pagesize
     * @param jobGroup         job group
     * @param jobId            job id
     * @param triggerTimeStart trigger time start
     * @param triggerTimeEnd   trigger time end
     * @param logStatus        log status
     * @return the list
     */
// exist jobId not use jobGroup, not exist use jobGroup
    public List<AfsJobLog> pageList(@Param("offset") int offset,
                                    @Param("pagesize") int pagesize,
                                    @Param("jobGroup") int jobGroup,
                                    @Param("jobId") int jobId,
                                    @Param("triggerTimeStart") Date triggerTimeStart,
                                    @Param("triggerTimeEnd") Date triggerTimeEnd,
                                    @Param("logStatus") int logStatus);

    /**
     * Page list count int
     *
     * @param offset           offset
     * @param pagesize         pagesize
     * @param jobGroup         job group
     * @param jobId            job id
     * @param triggerTimeStart trigger time start
     * @param triggerTimeEnd   trigger time end
     * @param logStatus        log status
     * @return the int
     */
    public int pageListCount(@Param("offset") int offset,
                             @Param("pagesize") int pagesize,
                             @Param("jobGroup") int jobGroup,
                             @Param("jobId") int jobId,
                             @Param("triggerTimeStart") Date triggerTimeStart,
                             @Param("triggerTimeEnd") Date triggerTimeEnd,
                             @Param("logStatus") int logStatus);

    /**
     * Load afs job log
     *
     * @param id id
     * @return the afs job log
     */
    public AfsJobLog load(@Param("id") long id);

    /**
     * Save long
     *
     * @param afsJobLog afs job log
     * @return the long
     */
    public long save(AfsJobLog afsJobLog);

    /**
     * Update trigger info int
     *
     * @param afsJobLog afs job log
     * @return the int
     */
    public int updateTriggerInfo(AfsJobLog afsJobLog);

    /**
     * Update handle info int
     *
     * @param afsJobLog afs job log
     * @return the int
     */
    public int updateHandleInfo(AfsJobLog afsJobLog);

    /**
     * Delete int
     *
     * @param jobId job id
     * @return the int
     */
    public int delete(@Param("jobId") int jobId);

    /**
     * Find log report map
     *
     * @param from from
     * @param to   to
     * @return the map
     */
    public Map<String, Object> findLogReport(@Param("from") Date from,
                                             @Param("to") Date to);

    /**
     * Find clear log ids list
     *
     * @param jobGroup        job group
     * @param jobId           job id
     * @param clearBeforeTime clear before time
     * @param clearBeforeNum  clear before num
     * @param pagesize        pagesize
     * @return the list
     */
    public List<Long> findClearLogIds(@Param("jobGroup") int jobGroup,
                                      @Param("jobId") int jobId,
                                      @Param("clearBeforeTime") Date clearBeforeTime,
                                      @Param("clearBeforeNum") int clearBeforeNum,
                                      @Param("pagesize") int pagesize);

    /**
     * Clear log int
     *
     * @param logIds log ids
     * @return the int
     */
    public int clearLog(@Param("logIds") List<Long> logIds);

    /**
     * Find fail job log ids list
     *
     * @param pagesize pagesize
     * @return the list
     */
    public List<Long> findFailJobLogIds(@Param("pagesize") int pagesize);

    /**
     * Update alarm status int
     *
     * @param logId          log id
     * @param oldAlarmStatus old alarm status
     * @param newAlarmStatus new alarm status
     * @return the int
     */
    public int updateAlarmStatus(@Param("logId") long logId,
                                 @Param("oldAlarmStatus") int oldAlarmStatus,
                                 @Param("newAlarmStatus") int newAlarmStatus);

}
